package com.techpleiad.ieducation.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.dao.DataAccessException;

/**
 * The Interface IAbstractDao.
 *
 * @param <T> the generic type
 * @param <K> the key type
 * 
 */
public interface IAbstractDao<T extends Serializable, K extends Serializable> {

	/**
	 * Update/delete all objects according to the given query.
	 *
	 * @param entity the entity
	 * @return the t
	 */
	void delete(final T entity) throws DataAccessException;

    /**
     * Persist the given transient instance.
     *
     * @param entity the entity
     * @return the t
     */
    K save(final T entity) throws DataAccessException;

    /**
     * Update the given persistent instance, associating it with the current Hibernate org.hibernate.Session.
     *
     * @param entity the entity
     * @return the t
     */
    void update(final T entity) throws DataAccessException;

    /**
     * Copy the state of the given object onto the persistent object with the same identifier
     *
     * @param entity the entity
     * @return the t
     */
    T merge(final T entity) throws DataAccessException;

    /**
	 * Save or update the given persistent instance, according to its id.
	 * Associates the instance with the current Hibernate org.hibernate.Session.
	 *
	 * @param entity the entity
	 */
    void saveOrUpdate(final T entity) throws DataAccessException;

    /**
	 * Save or update all given persistent instances, according to its id.
	 * Associates the instances with the current Hibernate Session.
	 *
	 * @param entities
	 * @return
	 */
    void saveOrUpdateAll(final Collection<T> entities) throws DataAccessException;

    /**
     * Execute an HQL query.
     *
     * @param query the query
     * @return the list
     */
    @SuppressWarnings("rawtypes")
	List findByQuery(final String query) throws DataAccessException;

    /**
     * Execute an HQL query, binding a number of values to "?" parameters in the query string.
     *
     * @param query the query
     * @param values the values
     * @return the list
     */
    @SuppressWarnings("rawtypes")
	List findByQuery(final String query, final Object...values) throws DataAccessException;


    /**
     * Find all.
     *
     * @return the list
     */
    List<T> findAll() throws DataAccessException;

    /**
     * Execute a query based on a given Hibernate criteria object.
     *
     * @param detachedCriteria the detached criteria
     * @return the list
     */
    @SuppressWarnings("rawtypes")
	List findByCriteria(final DetachedCriteria detachedCriteria) throws DataAccessException;

    /**
     * Execute a query based on the given Hibernate criteria object.
     *
     * @param criteria the criteria
     * @param firstResult the first result
     * @param maxResults the max results
     * @return the list
     */
    @SuppressWarnings("rawtypes")
	List findByCriteria(final DetachedCriteria criteria, final int firstResult, final int maxResults) throws DataAccessException;

    /**
     * Update/delete all objects according to the given query.
     *
     * @param queryString the query string
     * @return the t
     */
    int bulkUpdate(final String queryString) throws DataAccessException;

    /**
     * Update/delete all objects according to the given query.
     *
     * @param queryString the query string
     * @param value the value
     * @return the t
     */
    int bulkUpdate(final String queryString, final Object value) throws DataAccessException;

    /**
     * Update/delete all objects according to the given query.
     *
     * @param queryString the query string
     * @param value the value
     * @return the t
     */
    int bulkUpdate(final String queryString, final Object... values) throws DataAccessException;
    
    /**
	 * Removes all persistent instance from the datastore.
	 *
	 * @param entities
	 * @return
	 */
    void deleteAll(final Collection<T> entities) throws DataAccessException;
}
